package com.east.sng.service.impl;

import com.east.sng.dao.UserDao;
import com.east.sng.entity.param.UserParam;
import com.east.sng.entity.result.UserFind;
import com.east.sng.entity.result.UserInfo;
import com.east.sng.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author east
 * @date: 2020/12/27
 * @Description:
 **/
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserDao userDao;

    @Override
    public List<UserInfo> findUserRoles(Map<String, Object> params) {
        return userDao.selectUserRoles(params);
    }

    @Override
    public UserFind findUser(String userName) {
        return userDao.selectUser(userName);
    }

    @Override
    public void addUser(UserParam user) {
        userDao.insertUser(user);
    }

    @Override
    public void editUserPassword(UserParam user) {
        userDao.updateUserPassword(user);
    }

    @Override
    public boolean assignUserRole(Integer roleId, Integer userId) {
        return userDao.updateUserRole(roleId, userId)>0;
    }

    @Override
    public boolean checkUserName(String userName) {
        return userDao.selectUser(userName)==null;
    }

    @Override
    public boolean removeUser(Integer userId) {
        return userDao.deleteOrRecoverUser(userId,1)>0;
    }

    @Override
    public boolean batchRemoveUsers(List<Integer> userIds) {
        return userDao.batchDeleteOrRecoverUsers(userIds,1)>0;
    }

    @Override
    public boolean recoverUser(Integer userId) {
        return userDao.deleteOrRecoverUser(userId,0)>0;
    }

    @Override
    public boolean batchRecoverUsers(List<Integer> userIds) {
        return userDao.batchDeleteOrRecoverUsers(userIds,0)>0;
    }

}
